home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / exampl2.spr < prev    next >
Text File  |  1980-01-01  |  2KB  |  55 lines

  1. /* exampl2.spr */
  2. /*
  3.    Try the following questions
  4.    (japanese_car_pecentage france Percentage)
  5.    or
  6.    (japanese_car_percentage Country 63.5)
  7.    for example
  8.  */
  9.  
  10. /* market penetration of Japanese cars in Europe, 1980 figures */
  11. (japanese_car_percentage iceland 63.5)
  12. (japanese_car_percentage greece 49.2)
  13. (japanese_car_percentage norway 39.2)
  14. (japanese_car_percentage finland 35.5)
  15. (japanese_car_percentage ireland 31.3)
  16. (japanese_car_percentage denmark 31.0)
  17. (japanese_car_percentage holland 26.5)
  18. (japanese_car_percentage belgium 24.3)
  19. (japanese_car_percentage switzerland 23.1)
  20. (japanese_car_percentage austria 20.9)
  21. (japanese_car_percentage sweden 14.2)
  22. (japanese_car_percentage great_britain 11.9)
  23. (japanese_car_percentage west_germany 10.6)
  24. (japanese_car_percentage portugal 7.6)
  25. (japanese_car_percentage france 2.9) /* honestly */
  26.  
  27. /* now this may make you wonder about more sophisticated
  28.    questions like:
  29.    What countries have a japanese car percentage greater
  30.    than 30 percent?
  31.    What is the country that has the lowest Japanese car 
  32.    precentage?
  33.    The query for the second question is easy: it's a 
  34.    question in two parts: The first gets the percentage for the
  35.    country, the second just retains those percentages that
  36.    are above 30.0 . That's a calculation or a call to a
  37.    builtin "rless".
  38.    The whole query turns out to look like this:
  39.     ((japanese_car_percentage Country Percentage)(rless 30.0 Percentage))
  40.    Note the outer brackets.
  41.    We are asking for a solution to both parts at a time.
  42.    Prolog works from left to right, and "bactracks" to the left
  43.    when it cant solve one of the subproblems (or "goals").
  44.  
  45.    Prolog turns out to be more clumsy than SQL in formulating
  46.    the second query.
  47.    You need to define a few procedures, and the solution is way
  48.    beyond the scope of the pedagogical progression, but 
  49.    here is the general idea:
  50.    First form the list of all pairs of countries and their
  51.    corresponding percentages, then use a routine that picks out
  52.    the pair whose second part is the least of the lot.
  53.    We shall come back to that latter.
  54. */
  55.